<?php 
include 'include/init.php';
include 'include/mysql.config.php';
include 'include/common.fun.php';
include 'data/common_data.php';
if (isset($_POST)) {
	if (isset($_POST['username'])&&empty($_POST["username"])) {
    	$nameErr = "*姓名是必填的";
   	}else{
   		$username=$_POST["username"];
   	}
   if (isset($_POST['email'])&&empty($_POST['email'])) {
		$emailErr='*电邮是必填的';
	}elseif (!empty($_POST['email'])&&!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $_POST['email'])) {
		$emailErr='*电邮格式不正确';
	}else{
		$email=$_POST['email'];
	}
	if (isset($_POST['comment'])&&empty($_POST['comment'])) {
		$commentErr='请输入内容';
	}else{
		$comment=$_POST['comment'];
	}
	if (isset($_POST['number'])&&empty($_POST['number'])) {
		$numberErr='请输入手机号';
	}elseif(!empty($_POST['number'])&&!preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/",$_POST['number'])){
		$numberErr='手机号不正确';
	}else{
		$number=$_POST['number'];
	}
	if($username&&$email&&$number&&$comment) {
		$date=array(
			'user_name' => $username,
			'user_email' => $email,
			'user_tel' => $number,
			'msg_content' => $comment,
			'msg_addtime'=>time()
		);
		$res=$db->insert('wd_message',$date);
		if ($res) {
			alert('发送成功','contact.php');
		}else{
			alert('发送失败');
		}
	}
}
	

include 'view/contact.php';